package Maps 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;	
	/**
	 * ...
	 * @author Serg de Adelantado
	 */
	public class Tooltip extends CommonTooltip 
	{		
		static public const ID_COLOR:uint = 0xBC4A7B;
		
		static public const PRICE_CREDIT:String = 'Цена в рассрочку';
		static public const PRICE:String = 'Цена единовременно';
		static public const AREA:String = 'Площадь';
		
		private var FID:TooltipHeader;
		private var FStatus:TooltipHeader;		
		private var FArea:TooltipField;
		private var FPriceCredit:TooltipField;
		private var FPrice:TooltipField;
		private var FNoData:TooltipField;
		private var FFields:Vector.<TooltipField>;
		
		public function Tooltip()
		{
			super();
			FID = AddHeaderQuad(32, 0, COLOR);			
			FStatus = AddHeaderQuad(width - FID.width, 0x749E76, COLOR);
			FStatus.x = FID.width;
			
			FFields = new Vector.<TooltipField>;
			
			FArea = AddFiled(AREA, FStatus.height);			
			FPriceCredit = AddFiled(PRICE_CREDIT, FArea.y + FArea.height);			
			FPrice = AddFiled(PRICE, FPriceCredit.y + FPriceCredit.height);
			FNoData = AddFiled('Данные по участку', FPrice.y + FPrice.height);
			FNoData.Value = 'Не обнаружено';
			filters = [new DropShadowFilter(2, 45, 0, 1, 8, 8, 0.5, 3)];
		}		
		
		private function AddFiled(ALabel:String, AY:Number):TooltipField
		{
			var vResult:TooltipField = new TooltipField(ALabel);
			vResult.y = AY;
			addChild(vResult);
			FFields.push(vResult);
			return vResult;
		}
		
		private function AddHeaderQuad(AWidth:int, AColor:uint, ATextColor:uint):TooltipHeader 
		{
			var vResult:TooltipHeader = new TooltipHeader(AWidth, AColor, ATextColor);			
			addChild(vResult);
			return vResult;
		}
		
		public function set Region(ARegion:MapRegion):void 
		{			
			FID.Value = ARegion.ID.toString();
			Status = ARegion.Status;
			
			FPrice.visible = ARegion.Price != '';
			FPriceCredit.visible = ARegion.PriceCredit != '';
			FArea.visible = ARegion.Size != '';
			
			FPrice.Value = ARegion.Price;
			FPriceCredit.Value = ARegion.PriceCredit;
			FArea.Value = ARegion.Size;
			FNoData.visible = !FPrice.visible && !FPriceCredit.visible && !FArea.visible;
			
			var vMaxWidth:Number = 0;
			var vHeight:Number = FID.height;
			var vY:Number = 0;
			for (var i in FFields)
				FFields[i].DoAlign();
			for (var i in FFields)
			{
				if (FFields[i].visible)
				{
					FFields[i].y = FID.height + vY + 4;
					vHeight += FFields[i].height;
					if (FFields[i].width > vMaxWidth)				
						vMaxWidth = FFields[i].width;
					vY += FFields[i].height;
				}
			}
			vHeight += 8;
			vMaxWidth += 8;
			SetSize(vMaxWidth, vHeight);
			for (var i in FFields)
			{
				FFields[i].x = 4;				
				FFields[i].DoAlign(vMaxWidth - 8);
			}
			FStatus.Width = vMaxWidth - FID.width;
		}
		
		public function set Status(AStatus:int):void 
		{
			switch (AStatus) 
			{
				case 1:
					FStatus.Value = 'Продан';
					FStatus.Color = 0xC04548;
				break;
				case 2:
					FStatus.Value = 'Зарезервирован';
					FStatus.Color = 0xC19637;
				break;
				case 3:
					FStatus.Value = 'В продаже';
					FStatus.Color = 0x749E76;
				break;
				default:
					FStatus.Value = '-';
				break;
			}
		}
	}
}